<?php
/**
 * Created by PhpStorm.
 * User: River
 * Email: river0428@gmail.com
 * Date: 2018/10/30
 * Time: 上午10:27
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Coupon extends Model
{
    use SoftDeletes;

    protected $table = 'coupon';

    public $appends = ['type_name'];

    // 1代金券，2特权权
    const TYPE_MONEY    = 1;
    const TYPE_RECHARGE = 2;

    const EXPIRE_TYPE1 = 1;
    const EXPIRE_TYPE2 = 2;

    protected $guarded = [];

    public function recharge()
    {
        return $this->belongsTo(Recharge::class);
    }

    public function getTypeNameAttribute()
    {
        if ($this->type == self::TYPE_MONEY) {
            return '代金券';
        }
        if ($this->type == self::TYPE_RECHARGE) {
            return '特权券';
        }
        return '未定义';
    }

}